<template>
	<view class="pages">
		<com-head textTit="评价列表" :typeVal="1" :scrollTop="scrollTop"></com-head>
		
		<template v-if="list.length">
			<view class="comment" v-for="(item,index) in list" :key="index">
				<view class="user-box">
					<image :src="item.user.avatar" mode="aspectFill"></image>
					<view class="user-name">{{item.user.username}}</view>
					<view class="time left-auto">{{item.create_time}}</view>
					<view class="star">{{item.project_score}}星好评</view>
				</view>
				<view class="comment-center">
					<view>{{item.content}}</view>
					<view class="images" v-if="item.files.length">
						<image @click="utlis.previewImage(item.files)" v-for="(ele,index1) in item.files" :key="index1" :src="ele" mode="aspectFill"></image>
					</view>
				</view>
				<view class="goods" v-if="item.ordersProject">
					<image :src="item.ordersProject.project_images[0]" mode="aspectFill"></image>
					<view>
						<view class="t1">{{item.ordersProject.project_name}}</view>
						<view class="t2">
							<text>{{item.ordersProject.duration}}分钟</text>
							<text>X{{item.ordersProject.number}}</text>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore margin-top="60" margin-bottom="50" :status="status" />
		</template>
		<view class="noDate" v-else>
			<image src="https://willmid-img.oss-cn-shanghai.aliyuncs.com/2021/09/10/2x-8.png" mode=""></image>
			<view>暂无更多评论~</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goods_id:'',
				status:'loading',
				total:0,
				page:1,
				list:[],
				scrollTop: 0
			};
		},
		onPageScroll(e){
			this.scrollTop = e.scrollTop
		},
		onLoad({peoject_id}) {
			this.peoject_id = peoject_id
			this.getComment()
		},
		onReachBottom() {
			if (this.total > this.list.length) {
				this.page++;
				this.getComment();
			}
		},
		methods:{
			async getComment(ele){
				let {data,code} = await this.$u.api.getUserProjectComment({id:this.peoject_id,page:this.page});
				if(this.page == 1 && !data.data.lenght){
					this.status = 'nomore';
				}
				this.list = [...this.list, ...data.data];
				this.list.forEach((ele)=>{
					if(ele.files){
						ele.files = ele.files.split(",")
					}
					if(ele.ordersProject){
						ele.ordersProject.project_images = ele.ordersProject.project_images.split(",")
					}
				})
				console.log(this.list,"this.list")
				this.total = data.total;
				if (this.total <= this.list.length) this.status = 'nomore';
				else this.status = 'loading';
			},
		}
	}
</script>

<style>
	page{
		background-color: #F6F7FA;
	}
</style>
<style lang="scss" scoped>
.pages{
	padding: 50rpx 32rpx;
	.noDate{
		width: 360rpx;
		position: absolute;
		left: 50%;
		top: 34%;
		transform: translate(-50%,-50%);
		color: #666666;
		font-size: 26rpx;
		text-align: center;
		image{
			width: 360rpx;
			height: 310rpx;
			display: block;
			margin-bottom: 78rpx;
		}
	}
	.comment{
		background: #ffffff;
		border-radius: 20rpx;
		padding: 32rpx;
		margin-bottom: 30rpx;
		.user-box{
			display: flex;
			align-items: center;
			image{
				width: 48rpx;
				height: 48rpx;
				border-radius: 50%;
			}
			.user-name{
				margin-left: 12rpx;
				font-size: 24rpx;
				font-weight: 400;
				text-align: left;
				color: #333333;
				line-height: 26rpx;
			}
			.time{
				font-size: 24rpx;
				font-weight: 400;
				text-align: left;
				color: #999999;
				line-height: 26rpx;
			}
			.star{
				font-size: 24rpx;
				font-weight: 400;
				text-align: right;
				color: #bca364;
				line-height: 33rpx;
				margin-left: 14rpx;
			}
		}
		.comment-center{
			padding: 30rpx 0;
			.images{
				display: flex;
				flex-wrap: wrap;
				margin-top: 32rpx;
			}
			image{
				width: 132rpx;
				height: 132rpx;
				border-radius: 10rpx;
				margin-right: 26rpx;
				margin-bottom: 20rpx;
			}
		}
		.goods{
			border-top: 1px solid #d8d8d8;
			padding-top: 31rpx;
			display: flex;
			image{
				width: 99rpx;
				height: 99rpx;
				border-radius: 10rpx;
				margin-right: 24rpx;
			}
			.t1{
				margin-bottom: 10rpx;
				font-size: 32rpx;
				font-weight: 400;
				text-align: left;
				color: #000000;
				line-height: 45rpx;
			}
			.t2{
				width: 480rpx;
				display: flex;
				justify-content: space-between;
				font-size: 24rpx;
				font-weight: 400;
				text-align: left;
				color: #666666;
				line-height: 33rpx;
			}
		}
	}
}
</style>
